<template>
  <BasicPopup v-bind="$attrs" @register="registerPopup" :title="getTitle" showOkBtn @ok="handleSubmit">
    <a-alert :message="getDefaultPassword" type="warning" showIcon class="!mx-20px" />
    <BasicForm @register="registerForm" class="!px-30px" />
    <div class="jtcy-box" v-if="getTitle == '编辑'">
      <div class="jtcy-tit">
        <p>家庭成员</p>
      </div>
      <div class="jtcy-bg" v-for="(item,index) in jtcyData" :key="index">
        <div>
          <a-descriptions :title=" '关系 - ' + item.gx" bordered size="middle">
            <a-descriptions-item label="亲属姓名" style="width: 220px;"> {{ item.qsxm }}</a-descriptions-item>
            <a-descriptions-item label="性别"> {{ item.xb }}</a-descriptions-item>
            <a-descriptions-item label="出生日期"> {{ item.csrq }}</a-descriptions-item>
            <a-descriptions-item label="人员身份"> {{ item.rysf }}</a-descriptions-item>
            <a-descriptions-item label="人员职务"> {{ item.ryzw }}</a-descriptions-item>
            <a-descriptions-item label="人员现状"> {{ item.ryxz }}</a-descriptions-item>
            <a-descriptions-item label="工作单位"> {{ item.gzdw }}</a-descriptions-item>
          </a-descriptions>
        </div>
      </div>
      <a-empty v-if="jtcyData.length == 0" style="margin-top: 16px;" />
    </div>
  </BasicPopup>
</template>
<script lang="ts" setup>
  import { createUser, updateUser, getUserInfo, getPreview } from '/@/api/permission/user';
  import { getPositionByOrganize } from '/@/api/permission/position';
  import { getRoleByOrganize } from '/@/api/permission/role';
  import { ref, unref, computed } from 'vue';
  import { BasicPopup, usePopupInner } from '/@/components/Popup';
  import { BasicForm, useForm, FormSchema } from '/@/components/Form';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useBaseStore } from '/@/store/modules/base';
  import formValidate from '/@/utils/formValidate';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useAppStore } from '/@/store/modules/app';
  import { useUserStore } from '/@/store/modules/user';
  import { Empty } from 'ant-design-vue';
  const AEmpty = Empty;
  const appStore = useAppStore();

  const emit = defineEmits(['register', 'reload']);
  const { createMessage } = useMessage();
  const { t } = useI18n();
  const baseStore = useBaseStore();
  const userStore = useUserStore();
  const isAdministrator = userStore.getUserInfo.isAdministrator;
  let roleList = ref([])
  const schemas: FormSchema[] = [



    {
      field: 'groupTitleField1',
      label: '',
      component: 'GroupTitle',
      componentProps: { content: '编制信息' },
      colProps: { sm: 24, span: 24 },
    },
    {
      field: 'account',
      label: '警号',
      
      component: 'Input',
      componentProps: { placeholder: '请输入', maxlength: 50 },
      rules: [
        { required: true, trigger: 'blur', message: '必填' },
        { validator: formValidate('fullName', '不能含有特殊符号'), trigger: 'blur' },
      ],
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'realName',
      label: '姓名',
      
      component: 'Input',
      componentProps: { placeholder: '请输入', maxlength: 50 },
      rules: [
        { required: true, trigger: 'blur', message: '必填' },
        { validator: formValidate('fullName', '不能含有特殊符号'), trigger: 'blur' },
      ],
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'gender',
      label: '性别',
      
      component: 'Select',
      componentProps: { placeholder: '请选择', fieldNames: { value: 'enCode' }, showSearch: true },
      rules: [{ required: true, trigger: 'blur', message: '必填' }],
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'birthday',
      label: '出生日期',
      
      component: 'DatePicker',
      componentProps: { required: true,placeholder: '请选择' },
      colProps: { sm: 8, span: 8 },
      rules: [
        { required: true, trigger: 'blur', message: '必填' },
      ],
    },
    {
      field: 'organizeIdTreeBz',
      label: '编制部门',
      colProps: { sm: 8, span: 8 },

      component: 'OrganizeSelect',
      componentProps: { placeholder: '请选择', multiple: false, auth: true, onChange: onBzbmChange },
      rules: [{ required: true, trigger: 'blur', message: '必填', type: 'array' }],
    },
    {
      field: 'nation',
      label: '民族',
      rules: [
        { required: true, trigger: 'blur', message: '必填' },
      ],
      component: 'Select',
      componentProps: { placeholder: '请选择', showSearch: true },
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'cjgzsj',
      label: '参加工作时间',
      
      component: 'DatePicker',
      componentProps: { placeholder: '请选择' },
      colProps: { sm: 8, span: 8 },
      rules: [
        { required: true, trigger: 'blur', message: '必填' },

      ],
    },
    {
      field: 'gljz',
      label: '工龄校正',
      
      component: 'Input',
      componentProps: { placeholder: '请输入', maxlength: 50 },
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'zzmm',
      label: '政治面貌',
      rules: [
        { required: true, trigger: 'blur', message: '必填' },
      ],
      component: 'Input',
      componentProps: { placeholder: '请输入', maxlength: 50 },
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'nativePlace',
      label: '籍贯',
      rules: [
        { required: true, trigger: 'blur', message: '必填' },
      ],
      component: 'Input',
      componentProps: { placeholder: '请输入', maxlength: 100 },
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'certificatesNumber',
      label: '身份证',
      rules: [
        { required: true, trigger: 'blur', message: '必填' },
      ],
      component: 'Input',
      componentProps: { placeholder: '请输入', maxlength: 50 },
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'ryzt',
      label: '人员状态',
      
      component: 'Select',
      componentProps: { placeholder: '请选择', showSearch: true },
      colProps: { sm: 8, span: 8 },
      rules: [
        { required: true, trigger: 'blur', message: '必填' },
      ],
    },
    {
      field: 'hyzk',
      label: '婚姻状况',
      rules: [
        { required: true, trigger: 'blur', message: '必填' },
      ],
      component: 'Select',
      componentProps: { placeholder: '请选择', showSearch: true },
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'ryssbmjz',
      label: '部门与警种',
      rules: [
        { required: true, trigger: 'blur', message: '必填' },
      ],
      component: 'Input',
      componentProps: { placeholder: '请输入', maxlength: 50 },
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'rysf',
      label: '人员身份',
      
      component: 'Select',
      componentProps: { placeholder: '请选择', showSearch: true },
      colProps: { sm: 8, span: 8 },
      rules: [
        { required: true, trigger: 'blur', message: '必填' },
      ],
    },
    {
      field: 'dzwms',
      label: '多职务描述',
      
      component: 'Input',
      componentProps: { placeholder: '请输入', maxlength: 50 },
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'zw',
      label: '职务名称',
      
      component: 'Select',
      componentProps: { placeholder: '请选择', multiple: true, showSearch: true, fieldNames: { options: 'children' }, },
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'zwjb',
      label: '职务级别',
      
      component: 'Select',
      componentProps: { placeholder: '请选择', showSearch: true },
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'ranks',
      label: '职级',
      
      component: 'Select',
      componentProps: { placeholder: '请选择', showSearch: true },
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'bzcylb',
      label: '成员类别',
      
      component: 'Select',
      componentProps: { placeholder: '请选择', 
        options: [
          { fullName: '正职', id: '正职' },
          { fullName: '副职', id: '副职' },
          { fullName: '其他', id: '其他' },
        ], },
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'sfbdwdwbzcy',
      label: '党委班子成员',
      
      component: 'Select',
      componentProps: { placeholder: '请选择',
      options: [
          { fullName: '是', id: '是' },
          { fullName: '否', id: '否' },
        ],
       },
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'cjzzsj',
      label: '参加公安工作',
      rules: [
        { required: true, trigger: 'blur', message: '必填' },
      ],
      component: 'DatePicker',
      componentProps: { placeholder: '请选择' },
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'ly',
      label: '来源',
      
      component: 'Select',
      componentProps: { required: true,placeholder: '请选择', 
        options: [
          { fullName: '编制', id: '编制' },
          { fullName: '新增', id: '新增' },

        ], },
      colProps: { sm: 8, span: 8 },
      rules: [
        { required: true, trigger: 'blur', message: '必填' },
      ],
    },
    {
      field: 'sfdszn',
      label: '是否独生子女',
      
      component: 'Select',
      componentProps: { placeholder: '请选择', 
        options: [
          { fullName: '是', id: '是' },
          { fullName: '否', id: '否' },

        ], },
      colProps: { sm: 8, span: 8 },
      
    },
    {
     
     field: 'zgzt',
     label: '在岗状态',
     component: 'Select',
     componentProps: { required: true,placeholder: '请选择', 
       options: [
         { fullName: '在岗', id: '1' },
         { fullName: '不在岗', id: '0' },

       ], },
       colProps: { sm: 8, span: 8 },
       rules: [
        { required: true, trigger: 'blur', message: '必填' },
      ],
   },
    // {
    //   field: 'email',
    //   label: '电子邮箱',
    //   component: 'Input',
    //   componentProps: { placeholder: '请输入', maxlength: 50 },
    //   colProps: { sm: 8, span: 8 },
    // },
     {
      field: 'qwzt',
      label: '勤务状态',
      // rules: [
      //   { required: true, trigger: 'blur', message: '必填' },
      // ],
      component: 'Select',
      componentProps: { placeholder: '请选择', showSearch: true },
      colProps: { sm: 8, span: 8 },
    },
    // {
    //   field: 'positionId',
    //   label: '岗位',
    //   component: 'Select',
    //   componentProps: { placeholder: '请选择', multiple: true, showSearch: true, fieldNames: { options: 'children' }, onDropdownVisibleChange },
    // },

    {
      field: 'groupTitleField2',
      label: '',

      component: 'GroupTitle',
      componentProps: { content: '基本信息' },
      colProps: { sm: 24, span: 24 },
    },
    {
      field: 'headIcon',
      label: '头像',
      

      component: 'UploadImgSingle',
      componentProps: { tipText: '上传头像', type: 'userAvatar' },
      colProps: { sm: 24, span: 24 },
    },


    {
      field: 'organizeIdTree',
      label: '实际部门',
      
      component: 'OrganizeSelect',
      componentProps: { placeholder: '请选择', multiple: true, auth: true, onChange: onOrgChange },
      rules: [{ required: true, trigger: 'blur', message: '必填', type: 'array' }],
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'organizeIdTreeSjgzdd',
      label: '实际工作地点',
      component: 'OrganizeSelect',
      componentProps: { placeholder: '请选择', multiple: false, auth: true, onChange: onSjgzddChange },
      rules: [{ required: true, trigger: 'blur', message: '必填', type: 'array' }],
      colProps: { sm: 8, span: 8 },
    },
    
    {
      field: 'roleId',
      label: '角色',
      component: 'Select',
      colProps: { sm: 8, span: 8 },
      componentProps: { placeholder: '请选择', multiple: true, showSearch: true, fieldNames: { options: 'children' }, onDropdownVisibleChange },
      rules: [{ required: true, trigger: 'blur', message: '必填', type: 'array' }],
    },
    {
      field: 'enabledMark',
      label: '状态',
      
      defaultValue: 1,
      component: 'Select',
      colProps: { sm: 8, span: 8 },
      componentProps: {
        placeholder: '请选择',
        options: [
          { fullName: '启用', id: 1 },
          { fullName: '锁定', id: 2 },
          { fullName: '禁用', id: 0 },
        ],
      },
    },
    {
      field: 'managerId',
      label: '直属主管',
      
      component: 'UserSelect',
      componentProps: { placeholder: '请选择' },
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'mobilePhone',
      label: '手机号码',
      rules: [
        { required: true, trigger: 'blur', message: '必填' },
      ],
      component: 'Input',
      componentProps: { placeholder: '请输入', maxlength: 20 },
      colProps: { sm: 8, span: 8 },
    },
    {
      field: 'urgentTelePhone',
      label: '备用手机号',
      component: 'Input',
      defaultValue: '0',
      rules: [
        { required: true, trigger: 'blur', message: '必填' },
      ],
      componentProps: { placeholder: '请输入', maxlength: 20 },
      colProps: { sm: 8, span: 8 },
    },

    {
      field: 'sortCode',
      label: '排序',

      defaultValue: 0,
      component: 'InputNumber',
      colProps: { sm: 8, span: 8 },
      componentProps: {
        min: 0,
        max: 999999,
      },
    },
    {
      field: 'postalAddress',
      label: '通讯地址',
  
      component: 'Textarea',
      colProps: { sm: 24, span: 24 },
      componentProps: { placeholder: '请输入', maxlength: 300 },
    },
    {
      field: 'description',
      label: '说明',

      component: 'Textarea',
      colProps: { sm: 24, span: 24 },
      componentProps: { placeholder: '请输入', maxlength: 300 },
    },

  ];
  const [registerForm, { setFieldsValue, resetFields, validate, updateSchema }] = useForm({
    baseColProps: { sm: 12, xs: 24 },
    labelWidth: 100,
    schemas: schemas,
  });
  const [registerPopup, { closePopup, changeLoading, changeOkLoading }] = usePopupInner(init);
  const id = ref('');
  const organizeIdTree = ref<any[]>([]);
  const organizeIdTreeBz = ref<any[]>([]);
  const organizeIdTreeSjgzdd = ref<any[]>([]);
  let g_bzbm = "";
  let sjgzdd = ""

  const getSysConfig = computed(() => appStore.getSysConfigInfo);
  const getTitle = computed(() => (!unref(id) ? t('common.addText') : t('common.editText')));
  const getDefaultPassword = computed(() => '新用户默认初始密码是' + unref(getSysConfig).newUserDefaultPassword || '0000');

  let jtcyData = []
  function init(data) {
    changeLoading(true);
    resetFields();
    id.value = data.id;
    updateSchema({ field: 'account', componentProps: { readonly: !!unref(id) } });
    getOptions();
    if (id.value) {
      // 获取家庭成员数据
      getPreview({ yhid: id.value }).then(res => {
        if(res.code == 200) {
          jtcyData = res.data
        }
      })
      .catch(() => {
        // changeOkLoading(false);
      });
      getUserInfo(id.value).then(res => {
        console.log('获取接口详情', res)
        updateSchema({ field: 'account', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'realName', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'gender', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'birthday', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'organizeIdTreeBz', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'organizeIdTreeSjgzdd', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        
        updateSchema({ field: 'nation', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'cjgzsj', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'gljz', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'zzmm', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'nativePlace', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'certificatesNumber', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'ryzt', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'hyzk', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'qwzt', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'ryssbmjz', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'rysf', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'dzwms', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'zw', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'zwjb', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'ranks', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'bzcylb', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'sfbdwdwbzcy', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'cjzzsj', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'sfdszn', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'ly', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'organizeIdTree', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'roleId', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });
        updateSchema({ field: 'managerId', componentProps: { disabled: isAdministrator && getTitle.value == '编辑' ? false : true } });

        const data = {
          ...res.data,
          roleId: res.data.roleId ? res.data.roleId.split(',') : [],
          positionId: res.data.positionId ? res.data.positionId.split(',') : [],
          zw: res.data.zw ? res.data.zw.split(',') : [],
        };
        g_bzbm = res.data.bzbm;
        sjgzdd = res.data.sjgzdd
        organizeIdTree.value = res.data.organizeIdTree || [];
        organizeIdTreeBz.value = res.data.organizeIdTreeBz || [];
        organizeIdTreeSjgzdd.value = res.data.organizeIdTreeSjgzdd || [];
        if (res.data.organizeIdTree?.length) getOptionsByOrgIds(res.data.organizeIdTree);
        if (res.data.organizeIdTreeBz?.length) getOptionsByOrgIds(res.data.organizeIdTreeBz);
        if (res.data.organizeIdTreeSjgzdd?.length) getOptionsByOrgIds(res.data.organizeIdTreeSjgzdd);
        roleList.value = data.roleId
        setFieldsValue(data);
        changeLoading(false);
      });
    } else {
      organizeIdTree.value = data.organizeIdTree?.length ? [data.organizeIdTree] : [];
      if (organizeIdTree.value?.length) getOptionsByOrgIds(organizeIdTree.value);
      setFieldsValue({ organizeIdTree: organizeIdTree.value });

      organizeIdTreeBz.value = data.organizeIdTreeBz?.length ? [data.organizeIdTreeBz] : [];
      if (organizeIdTreeBz.value?.length) getOptionsByOrgIds(organizeIdTreeBz.value);
      setFieldsValue({ organizeIdTreeBz: organizeIdTreeBz.value });

      organizeIdTreeSjgzdd.value = data.organizeIdTreeSjgzdd?.length ? [data.organizeIdTreeSjgzdd] : [];
      if (organizeIdTreeSjgzdd.value?.length) getOptionsByOrgIds(organizeIdTreeSjgzdd.value);
      setFieldsValue({ organizeIdTreeSjgzdd: organizeIdTreeSjgzdd.value });
      updateSchema({ field: 'positionId', componentProps: { options: [] } });
      updateSchema({ field: 'roleId', componentProps: { options: [] } });
      changeLoading(false);
    }
  }
  async function getOptions() {
    const sexRes = await baseStore.getDictionaryData('sex');
    updateSchema({ field: 'gender', componentProps: { options: sexRes } });
    const nationRes = await baseStore.getDictionaryData('Nation');
    updateSchema({ field: 'nation', componentProps: { options: nationRes } });
    const educationRes = await baseStore.getDictionaryData('Education');
    updateSchema({ field: 'education', componentProps: { options: educationRes } });
    const certificateTypeRes = await baseStore.getDictionaryData('certificateType');
    updateSchema({ field: 'certificatesType', componentProps: { options: certificateTypeRes } });
    // 人员身份
    const ywRysf = await baseStore.getDictionaryData('ywRysf');
    updateSchema({ field: 'rysf', componentProps: { options: ywRysf } });

    // 人员状态
    const ywRyzt = await baseStore.getDictionaryData('ywRyzt');
    updateSchema({ field: 'ryzt', componentProps: { options: ywRyzt } });
    
    //  婚姻状况
    const ywHyzk = await baseStore.getDictionaryData('ywHyzk');
    updateSchema({ field: 'hyzk', componentProps: { options: ywHyzk } });
    
    //  勤务状态
    const ywQwzt = await baseStore.getDictionaryData('ywQwzt');
    updateSchema({ field: 'qwzt', componentProps: { options: ywQwzt } });

    // 职务级别
    const ywZwjb = await baseStore.getDictionaryData('ywZwjb');
    updateSchema({ field: 'zwjb', componentProps: { options: ywZwjb } });
    
    // 职务
    const ywRyzw = await baseStore.getDictionaryData('ywRyzw');
    updateSchema({ field: 'zw', componentProps: { options: ywRyzw } });
    
    // 职级
    const ywRyzj = await baseStore.getDictionaryData('ywRyzj');
    updateSchema({ field: 'ranks', componentProps: { options: ywRyzj } });
  }
  function onDropdownVisibleChange(open) {
    if (!open) return;
    if (!organizeIdTree.value || !organizeIdTree.value.length) createMessage.warning('请先选择所属组织');
  }
  // 编制部门
  function onBzbmChange(val) {
    console.log('编制部门', val);
    g_bzbm = val[val.length-1];
    organizeIdTreeBz.value = val || [];
    if (!val || !val.length) return;
    //getOptionsByOrgIds(val);
  }

  // 实际工作地点
  function onSjgzddChange(val) {
    console.log('实际工作地点', val);
    sjgzdd = val[val.length-1];

    organizeIdTreeSjgzdd.value = val || [];
  
    if(val &&  roleList.value.indexOf('563756081143087365') == -1) {
      roleList.value.push('563756081143087365')
    }
    setFieldsValue({  roleId: roleList });
    if (!val || !val.length) {
      return
    } 
  }
  function onOrgChange(val) {
    setFieldsValue({ positionId: [], roleId: [] });
    organizeIdTree.value = val || [];
    if (!val || !val.length) return;
    getOptionsByOrgIds(val);
  }
  function getOptionsByOrgIds(organizeIdTree) {
    const organizeIds = organizeIdTree.map(o => o[o.length - 1]);
    getPositionByOrganize(organizeIds).then(res => {
      const list = res.data.list.filter(o => o.children && Array.isArray(o.children) && o.children.length);
      updateSchema({ field: 'positionId', componentProps: { options: list } });
    });
    getRoleByOrganize(organizeIds).then(res => {
      const list = res.data.list.filter(o => o.children && Array.isArray(o.children) && o.children.length);
      updateSchema({ field: 'roleId', componentProps: { options: list } });
    });
  }

  async function handleSubmit() {
    const values = await validate();
    if (!values) return;
    changeOkLoading(true);
    const organizeIds = values.organizeIdTree.map(o => o[o.length - 1]);

    //debugger
    console.log("bzbm:",values);

    const query = {
      ...values,
      id: id.value,
      organizeId: organizeIds.join(),
      positionId: values.positionId && values.positionId.length ? values.positionId.join() : '',
      roleId: values.roleId && values.roleId.length ? values.roleId.join() : '',
      bzbm: g_bzbm,
      sjgzdd,
      zw: values.zw && values.zw.length ? values.zw.join() : '',

    };
    console.log('传给后端的参数', query);
    const formMethod = id.value ? updateUser : createUser;
    formMethod(query)
      .then(res => {
        createMessage.success(res.msg);
        changeOkLoading(false);
        closePopup();
        emit('reload');
      })
      .catch(() => {
        changeOkLoading(false);
      });
  }
</script>
<style lang="less" scoped>
.jtcy-box {
  padding: 0 30px;
  display: flex;
  flex-direction: column;

  .jtcy-tit {
    flex: 1 1 0%;
    border-bottom: 1px solid #d9d9d9;

    p {
      position: relative;
      display: flex;
      font-size: 16px;
      font-weight: 500;
      line-height: 24px;
      color: rgb(0 0 0 / 85%);
      user-select: none;
      align-items: center;
      margin-bottom: 10px;
    }
  }

  .jtcy-bg {
    &:first-child {
      margin-top: -20px !important;
    }

    ::v-deep .ant-descriptions-header {
      margin-bottom: 10px;
      margin-top: 16px;
    }
  }
}

</style>
